package com.niit.order.service;

import com.niit.feign.pojo.User;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.SendTo;

/**
 * @author yaojianfeng
 * @EnableBinding 绑定通道
 */
@EnableBinding({Processor.class, SinkSender.class,MySource.class})
public class MessageReceiver {


    /**
     * 监听output2通道,完成自动类型转换
     *
     * @param user
     */
    @StreamListener("output2")
    public void receive(User user) {
        System.out.println("output2 Received: " + user);
    }

    @StreamListener("output1")
    public void outputMessage(Message<String> msg){
        System.out.println("output1 接收到的消息是: "+msg.getPayload());
    }

    @StreamListener(Sink.INPUT)
    @SendTo(Processor.OUTPUT)
    public String receiveMessage(Message<String> msg){
        System.out.println("order-service接收到的消息是: "+msg.getPayload());
        return msg.getPayload();
    }


}